﻿namespace Tomato.Allure.Samples
{
	public class SolutionCounter : AddOn
	{
		private SolutionCounterForm m_solutionCounterForm = null;

		private IVisualStudio m_visualStudio = null;

		public override bool OnStart( IVisualStudio visualStudio )
		{
			m_visualStudio = visualStudio;

			// Form
			m_solutionCounterForm = new SolutionCounterForm( visualStudio );

			return true;
		}

		public override bool OnEvent( IService allureService, AllureEvent allureEvent )
		{
			switch( allureEvent.EventType )
			{
				case EventType.SolutionOpened:
					{
						// 솔루션이 열렸을 때 이벤트 처리
						m_solutionCounterForm.OnOpenedSolution();
					}
					return true;
			}

			return false;
		}

		// 사용자가 애드인을 실행함
		public override bool OnExecute( IService allureService )
		{
			if( m_visualStudio.ActiveSolution.IsOpen )
			{
				m_solutionCounterForm.Execute();

				if( m_solutionCounterForm != null )
				{
					m_solutionCounterForm.ShowDialog();
				}
			}

			return true;
		}		
	}
}
